package com.example.john.adaptertest;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import org.apache.http.HttpEntity;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;

public class TestActivity extends AppCompatActivity {
    private ImageView iv;
    private Handler h;
    private EditText et;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        iv=(ImageView)findViewById(R.id.iv);
        et=(EditText)findViewById(R.id.et);
        h=new Handler(){
            @Override
            public void handleMessage(Message msg) {
              byte[] bs=msg.getData().getByteArray("data");
                iv.setImageBitmap(BitmapFactory.decodeByteArray(bs,0,bs.length));

            }
        };
    }

    public void test(View v){
        new Thread(){
            @Override
            public void run() {
                String fn=et.getText().toString();
                String url="http://192.168.10.214:8080/StuMs/tes1?fn="+fn;
                byte[] data=ImageViewUtil.decode(url,10240,256);
                Message msg=new Message();
                msg.getData().putByteArray("data",data);
                h.sendMessage(msg);


            }
        }.start();

    }

    public void test1(View v){
        Intent intent=new Intent();
        intent.setClass(this,MainActivity.class);
        startActivity(intent);
    }
}
